
<%@ page import="les.Usuario" %>
<html>
    <head>
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'usuario.label', default: 'Usuario')}" />
        <title>Listar Usuarios</title>
    </head>
    <body>
        <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}">Inicio</a></span>
        </div>
        <div class="body">
            <h1>Listar Usuarios</h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <div class="list">
                <table>
                    <thead>
                        <tr>
                        
                        
                            <g:sortableColumn property="email" title="${message(code: 'usuario.email.label', default: 'Email')}" />
                        
                            <g:sortableColumn property="tipo" title="${message(code: 'usuario.tipo.label', default: 'Tipo')}" />
                        
                        	<th>Deletar</th>
                        
                        </tr>
                    </thead>
                    <tbody>
                    <g:each in="${usuarioInstanceList}" status="i" var="usuarioInstance">
                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                        
                            <td><g:link action="show" id="${usuarioInstance.id}">${fieldValue(bean: usuarioInstance, field: "email")}</g:link></td>
                        
                            <td>${fieldValue(bean: usuarioInstance, field: "tipo")}</td>
                        
							<td>
								<g:if test="${session.usuarioLogado.tipo == 'Administrador' && session.usuarioLogado.email != usuarioInstance.email}">
									<g:form>
                    				<g:hiddenField name="id" value="${usuarioInstance?.id}" />
                    				<span class="button" id="deletar${usuarioInstance?.email}"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Voce tem certeza?')}');" /></span>
                					</g:form>									
								</g:if>
								<g:elseif test="${session.usuarioLogado.tipo == 'Jota' && session.usuarioLogado.email != usuarioInstance.email}">
									<g:if test="${usuarioInstance.tipo == 'Coordenador'}">
										<g:form>
                    					<g:hiddenField name="id" value="${usuarioInstance?.id}" />
                    					<span class="button"><g:actionSubmit name="deletar${usuarioInstance.email}" class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Voce tem certeza?')}');" /></span>
                						</g:form>									
									</g:if>
								</g:elseif>
							</td>
                        
                        </tr>
                    </g:each>
                    </tbody>
                </table>
            </div>
            <div class="paginateButtons">
                <g:paginate total="${usuarioInstanceTotal}" />
            </div>
        </div>
    </body>
</html>
